import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.MalformedURLException;
import java.net.URL;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.ImageIcon;
import javax.swing.JTextArea;

public class Chef extends JFrame implements ActionListener{

    private Toolkit toolkit;
   //static int i = 0;
    JLabel layout;
    JButton logout =new JButton("Log Out");
    JButton clear =new JButton("Clear Order");
    JButton[] t = new JButton[18];
    JTextArea orderlist1 =new JTextArea();
    login logger;
    OrderManagement orders;
    int st=0;
    int tabnum=0;
    
    public Chef()
    {
    	;
    }
    
    public Chef(login log, OrderManagement orderi) {
    	setTitle("Restaurant Master 2.0 - Chef");
        setSize(800, 600);
        
        logger=log;
        orders=orderi;
        toolkit = getToolkit();
        
        Dimension size = toolkit.getScreenSize();
        setLocation((size.width - getWidth())/2, (size.height - getHeight())/2);
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

        JPanel panel = new JPanel();
        getContentPane().add(panel);
        panel.setLayout(null);

		logout.addActionListener(this);
		logout.setBounds(25,525,100,30);
		panel.add(logout);
		
		clear.addActionListener(this);
		clear.setBounds(335,460,100,75);
		panel.add(clear);
		
		orderlist1 = new JTextArea("");
		orderlist1.setBounds(500,0,275,750);
		panel.add(orderlist1);
		
		for(int i=0;i<12;i++)
		{
			t[i]=new JButton(""+(i+1));
		}
		
		for(int i=0;i<12;i++)
		{
			t[i].addActionListener(this);
		}
		
		t[0].setBounds(0,0,200,75);
		t[1].setBounds(0,75,200, 75);
		t[2].setBounds(0,150,200,75);
		t[3].setBounds(0,225,200,75);
		t[4].setBounds(0,300,200,75);
		t[5].setBounds(0,375,200,75);
		
		t[6].setBounds(200,0,200,75);
		t[7].setBounds(200,75,200,75);
		t[8].setBounds(200,150,200,75);
		t[9].setBounds(200,225,200,75);
		t[10].setBounds(200,300,200,75);
		t[11].setBounds(200,375,200,75);
		
		for(int i=0;i<12;i++)
		{
			panel.add(t[i]);
		}
		
		
    }
    
    //event handler
    

    
    public void actionPerformed(ActionEvent event)
    {
    	Object source = event.getSource();
    	
    	
    	if (source == logout)
    	{
    		logger.setuid(null);
    		setVisible(false);
    	}
    	
    	if (source == clear)
    	{
    		orders.markComplete(tabnum);
    		refresh(0);
    		t[tabnum].setBackground(Color.gray);
    	}
    	
    	if (source == t[0])
    	{
    		refresh(1);
    		tabnum=1;
    	}
    	
    	if (source == t[1])
    	{
    		refresh(2);
    		tabnum=2;
    	}
    	
    	if (source == t[2])
    	{
    		refresh(3);
    		tabnum=3;
    	}
    	
    	if (source == t[3])
    	{
    		refresh(4);
    		tabnum=4;
    	}
    	
    	if (source == t[4])
    	{
    		refresh(5);
    		tabnum=5;
    	}
    	
    	if (source == t[5])
    	{
    		refresh(6);
    		tabnum=6;
    	}
    	
    	if (source == t[6])
    	{
    		refresh(7);
    		tabnum=7;
    	}
    	
    	if (source == t[7])
    	{
    		refresh(8);
    		tabnum=8;
    	}
    	
    	if (source == t[8])
    	{
    		refresh(9);
    		tabnum=9;
    	}
    	
    	if (source == t[9])
    	{
    		refresh(10);
    		tabnum=10;
    	}
    	
    	if (source == t[10])
    	{
    		refresh(11);
    		tabnum=11;
    	}
    	
    	if (source == t[11])
    	{
    		refresh(12);
    		tabnum=12;
    	}
    	
    	
    }
    
    public void refresh(int bnum)
    {
    		
    	orderlist1.setText(orders.printReceipt(bnum));
    	
    	for (int i=0;i<12;i++)
    	{
    		if (orders.printReceipt(i+1).equals(""))
    		{
    			t[i].setBackground(Color.gray);
    		}
    		else
    		{
    			t[i].setBackground(Color.green);
    		}
    			
    			
    	}
        	
	}
    
}

    
